package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Region;
import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.domain.StrategyComment;
import cn.wolfcode.trip.base.domain.Tag;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.StrategyCatalogQuery;
import cn.wolfcode.trip.base.query.StrategyCommentQuery;
import cn.wolfcode.trip.base.query.StrategyQuery;
import cn.wolfcode.trip.base.service.IRegionService;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import cn.wolfcode.trip.base.service.IStrategyCommentService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 大攻略资源控制器
 */
@RestController
@RequestMapping("/strategies")
public class StrategyController {
    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private IStrategyCatalogService catalogService;
    @Autowired
    private IStrategyCommentService commentService;

    /**
     * 根据攻略id查看所有目录
     * @return
     */
    @GetMapping("/{strategyId}/catalogs")
    public Object selectByStrateId(StrategyCatalogQuery qo){
        qo.setPageSize(0);
        qo.setOrderBy("sc.sequence");
        return catalogService.query(qo);
    }

    /**
     * 根据条件查询攻略
     * @param qo
     * @return
     */
    @GetMapping
    public Object select(StrategyQuery qo){
        qo.setPageSize(0);
        return strategyService.query(qo);
    }

    /**
     * 获取指定攻略的点评
     * @return
     */
    @GetMapping("/{strategyId}/comments")
    public Object selectCommentsById(StrategyCommentQuery qo){
        qo.setOrderBy("sc.createTime desc");
        return commentService.query(qo);
    }

    /**
     * 获取指定攻略的点评
     * @return
     */
    @PostMapping("/{strategy.id}/comments")
    public Object save(StrategyComment comment, String[] tagArr){
        commentService.save(comment,tagArr);
        return new JSONResult();
    }
}
